package com.zimin.cloud.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.netflix.discovery.converters.Auto;
import com.zimin.cloud.mine.pojo.system.business.DeptBO;
import com.zimin.cloud.mine.pojo.system.business.RoleBO;
import com.zimin.cloud.mine.pojo.system.view.DeptVO;
import com.zimin.cloud.system.pojo.entity.Dept;
import com.zimin.cloud.system.mapper.DeptMapper;
import com.zimin.cloud.system.pojo.entity.Role;
import com.zimin.cloud.system.service.IDeptService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zimin.common.utils.ObjectUtils;
import com.zimin.common.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 部门 服务实现类
 * </p>
 *
 * @author zimin
 * @since 2021-12-30 11:05
 */
@Service("deptService")
@Slf4j
public class DeptServiceImpl extends ServiceImpl<DeptMapper, Dept> implements IDeptService {

    @Autowired
    private DeptMapper deptMapper;

    @Override
    public Page<Dept> page(Page<Dept> deptPage, DeptBO deptBO) {
        return page(deptPage, queryWrappers(deptBO));
    }

    @Override
    public List<DeptVO> listVO(DeptBO deptBO) {
        return deptMapper.selectList(queryWrappers(deptBO), DeptVO.class);
    }

    /**
     * <p>查询wrappers</p>
     *
     * @param deptBO
     * @return com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper<com.zimin.cloud.system.pojo.entity.Dept>
     * @since 2022-02-19 17:12:37
     */
    public LambdaQueryWrapper<Dept> queryWrappers(DeptBO deptBO) {
        return Wrappers.<Dept>lambdaQuery()
                .like(ObjectUtils.isNotEmpty(deptBO.getDeptName()), Dept::getDeptName, deptBO.getDeptName())
                .eq(ObjectUtils.isNotEmpty(deptBO.getStatus()), Dept::getStatus, deptBO.getStatus())
                .orderByDesc(Dept::getCreateTime);
    }

}
